package com.ruoyi.web.controller.news.api;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.news.NewsMainBusiness;
import com.ruoyi.system.domain.news.query.NewsMainBusinessQuery;
import com.ruoyi.system.domain.news.vo.NewsMainBusinessVo;
import com.ruoyi.system.service.news.NewsMainBusinessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/news/newsMainBusiness")
@Api(value = "newsMainBusinessApiController", tags  = "主要业务Api")
public class NewsMainBusinessApiController extends BaseController {

	@Resource
	private NewsMainBusinessService newsMainBusinessService;

	@ApiOperation(value = "获取单个主要业务信息", notes = "获取单个主要业务信息")
	@GetMapping("/getById")
	public R<NewsMainBusiness> getById(@RequestParam(value = "id") Long id) {
		NewsMainBusinessQuery newsMainBusinessQuery = new NewsMainBusinessQuery();
		newsMainBusinessQuery.setId(id);
		List<NewsMainBusinessVo> newsMainBusinessList = newsMainBusinessService.getNewsMainBusinessList(newsMainBusinessQuery);
		if (newsMainBusinessList!=null&&newsMainBusinessList.size()>0) {
			return R.ok(newsMainBusinessList.get(0));
		} else {
			return R.fail("数据不存在");
		}
	}

	@ApiOperation(value = "获取主要业务信息列表")
	@PostMapping(value = "/list")
	public R<PageInfo<NewsMainBusinessVo>> list(@RequestBody NewsMainBusinessQuery newsMainBusinessQuery) {
        newsMainBusinessQuery.setIsEnable("1");
		List<NewsMainBusinessVo> newsMainBusinessList = newsMainBusinessService.getNewsMainBusinessList(newsMainBusinessQuery);
		return R.ok(new PageInfo<>(newsMainBusinessList));
	}
}
